//
//  publishCommitViewController.m
//  Findif
//
//  Created by Mac on 2018/12/3.
//  Copyright © 2018年 Cicel Chen. All rights reserved.
//

#import "publishCommitViewController.h"
#import "XHStarRateView.h"
#import "AddCommitView.h"
#import "PublishCommitTableViewCell.h"
#import "PushCommitModel.h"

@interface publishCommitViewController ()<UITextViewDelegate,UIImagePickerControllerDelegate, UINavigationControllerDelegate,UITableViewDelegate,UITableViewDataSource,AddCommitViewDelegate>{
    
    UIImagePickerController *_imagePickerController;
}

@property (nonatomic, strong)UIView * topView;
@property (nonatomic, strong)UIView * bottomView;
@property (nonatomic, weak)UILabel * titleLabel;
@property (nonatomic, weak)UITextView * commitTextView;
@property (nonatomic, strong)XHStarRateView * totalStartView;
//@property (nonatomic, strong)XHStarRateView * conformStartView;
//@property (nonatomic, strong)XHStarRateView * severiceStartView;
//@property (nonatomic, strong)XHStarRateView * goodStartView;
@property (nonatomic, weak)UIView * lineView;
@property (nonatomic, weak)UIImageView * shopImageView;
@property (nonatomic, weak)UILabel * bottomTitleLabel;
@property (nonatomic, weak)UILabel * exploreLabel;
//@property (nonatomic, strong)UILabel * conformLabel;
//@property (nonatomic, strong)UILabel * severLabel;
//@property (nonatomic, strong)UILabel * goodLabel;

@property (nonatomic, weak)UIImageView * iocnImageView;
@property (nonatomic, weak)UILabel * infoLabel;

@property (nonatomic, strong)AddCommitView * addView;
@property (nonatomic, assign)NSInteger count;
@property (nonatomic, strong)UIAlertController * alertVC;
@property (nonatomic, weak)UITableView * tableView;
@property (nonatomic, strong)NSArray<PushCommitModel *> * dataArray;
@property (nonatomic, strong)NSMutableArray * imgArray;
@property (nonatomic, copy)NSString * IDStr;


@end

@implementation publishCommitViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    _imagePickerController = [[UIImagePickerController alloc] init];
    _imagePickerController.delegate = self;
    _imagePickerController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    _imagePickerController.allowsEditing = YES;
    
    self.imgArray = [NSMutableArray array];
    
    [self setupNav];
    [self loadData];
    [self setupUI];
    [self setupAlertVC];
}

- (void)loadData{
    
    [[ZRNetworkTool sharedTool] getMerchantsCommentsRulesResultWithBlock:^(BOOL success, id responseData) {
        if (success) {

            self.dataArray = [NSArray yy_modelArrayWithClass:[PushCommitModel class] json:responseData[@"data"]];
        }
    }];
}

- (void)setDataArray:(NSArray<PushCommitModel *> *)dataArray{
    
    _dataArray = dataArray;
    
    PushCommitModel * model = dataArray.firstObject;
    self.titleLabel.text = model.merchants_comments_name;
    self.IDStr = model.id;
    
    [self.tableView reloadData];
}

- (void)setupNav{
    
    self.title = @"发表评论";
    
    //    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back(1)"] style:UIBarButtonItemStylePlain target:nil action:nil];
    //
    //    self.navigationItem.backBarButtonItem = backItem;
    
    UIButton * rightButton = [[UIButton alloc] init];
    
//    [rightButton setTitle:@"收支明细" forState:UIControlStateNormal];
    [rightButton setImage:[UIImage imageNamed:@"完成"] forState:UIControlStateNormal];
    [rightButton addTarget:self action:@selector(didRightButton) forControlEvents:UIControlEventTouchUpInside];
//    [rightButton setTitleColor:ZRBlackColor forState:UIControlStateNormal];
    
    UIBarButtonItem * rightBar = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
    
    self.navigationItem.rightBarButtonItem = rightBar;
}


- (void)setupUI{
    
    self.view.backgroundColor = ColorWithRGB(0xf6f7f8);
    
    self.topView = [[UIView alloc] initWithFrame:CGRectMake(15 * SCREENH6, kNavHeight + kStatusBarHeight + 10 * SCREENH6, kScreenW - 30 * SCREENH6, 240 * SCREENH6)];
    self.topView.backgroundColor = ZRWhiteColor;
    [self.view addSubview:self.topView];
    self.bottomView = [self setupView];
    [self.view addSubview:self.bottomView];
    
    UIImageView * iconImageView = [UIImageView new];
    
//    iconImageView.backgroundColor = [UIColor lightGrayColor];
    [iconImageView sd_setImageWithURL:self.goodUrl];
    
    self.iocnImageView = iconImageView;
    
    [self.topView addSubview:self.iocnImageView];
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.textColor = ZRBlackColor;
    titleLabel.text = @"商品评价";
    titleLabel.font = [UIFont boldSystemFontOfSize:16 * SCREENH6];
    
    self.titleLabel = titleLabel;
    
    [self.topView addSubview:self.titleLabel];

    self.totalStartView = [self setupStartViewWithFrame:CGRectMake(135 * SCREENH6, 21 * SCREENH6, 150 * SCREENH6, 20 * SCREENH6)];
    [self.topView addSubview:self.totalStartView];
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xe3e4e5);
    
    self.lineView = lineView;
    
    [self.topView addSubview:self.lineView];
    
    // 创建textView
    UITextView * infoTextView =[[UITextView alloc] init];
    
    infoTextView.backgroundColor= ZRWhiteColor;
    infoTextView.text = @"对这次购物体验满意吗？可以在这里说说你的感受哦！";
    infoTextView.font = [UIFont systemFontOfSize:14 * SCREENH6];
    infoTextView.textColor = ColorWithRGB(0xbebebe);
    infoTextView.delegate = self;
    
    self.commitTextView = infoTextView;
    [self.topView addSubview:self.commitTextView];
    
    self.addView = [[AddCommitView alloc] initWithFrame:CGRectMake(15 * SCREENH6, 150 * SCREENH6, kScreenW - 45 * SCREENH6, 85 * SCREENH6)];
    self.addView.addCommitViewDelegate = self;
    
    [self.topView addSubview:self.addView];
    
    
    UIImageView * shopImageView = [UIImageView new];
    
    shopImageView.image = [UIImage imageNamed:@"shop"];
    
    self.shopImageView = shopImageView;
    
    [self.bottomView addSubview:self.shopImageView];
    
    UILabel * bottomTitleLabel = [UILabel new];
    
    bottomTitleLabel.text = @"线下体验评价";
    bottomTitleLabel.textColor = ZRBlackColor;
    bottomTitleLabel.font = [UIFont systemFontOfSize:17 * SCREENH6];
    
    self.bottomTitleLabel = bottomTitleLabel;
    
    [self.bottomView addSubview:self.bottomTitleLabel];
    
    
    UILabel * exploreLabel = [UILabel new];
    
    exploreLabel.text = @"满意请给五颗星哦~";
    exploreLabel.textColor = [UIColor lightGrayColor];
    exploreLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    
    self.exploreLabel = exploreLabel;
    
    [self.bottomView addSubview:self.exploreLabel];
    
//    self.conformLabel = [self setupLabelWithString:@"商品符合度"];
//    [self.bottomView addSubview:self.conformLabel];
//    self.conformStartView = [self setupStartViewWithFrame:CGRectMake(205 * SCREENH6, 56 * SCREENH6, 130 * SCREENH6, 15 * SCREENH6)];
//    [self.bottomView addSubview:self.conformStartView];
//    self.severLabel = [self setupLabelWithString:@"店家服务态度"];
//    [self.bottomView addSubview:self.severLabel];
//    self.severiceStartView = [self setupStartViewWithFrame:CGRectMake(205 * SCREENH6, 82 * SCREENH6, 130 * SCREENH6, 15 * SCREENH6)];
//    [self.bottomView addSubview:self.severiceStartView];
//    self.goodLabel = [self setupLabelWithString:@"体验好感度"];
//    [self.bottomView addSubview:self.goodLabel];
//    self.goodStartView = [self setupStartViewWithFrame:CGRectMake(205 * SCREENH6, 112 * SCREENH6, 130 * SCREENH6, 15 * SCREENH6)];
//    [self.bottomView addSubview:self.goodStartView];
    
    UITableView * tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 45 * SCREENH6, 345 * SCREENH6, 200 * SCREENH6) style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.backgroundColor = ZRWhiteColor;
    tableView.rowHeight = 30 * SCREENH6;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

    self.tableView = tableView;
    
    [self.tableView registerClass:[PublishCommitTableViewCell class] forCellReuseIdentifier:@"PublishCommitTableViewCell"];
    
    [self.bottomView addSubview:self.tableView];
}

- (void)viewDidLayoutSubviews{
    
//    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(self.view).offset(15 * SCREENH6);
//        make.trailing.mas_equalTo(self.view).offset(-15 * SCREENH6);
//        make.top.mas_equalTo(self.view).offset(kNavHeight + kStatusBarHeight + 10 * SCREENH6);
//        make.height.mas_equalTo(250 * SCREENH6);
//    }];
    
    [self.iocnImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.topView).offset(15 * SCREENH6);
        make.top.mas_equalTo(self.topView).offset(10 * SCREENH6);
        make.width.height.mas_equalTo(45 * SCREENH6);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.iocnImageView.mas_trailing).offset(5 * SCREENH6);
        make.centerY.mas_equalTo(self.iocnImageView);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.iocnImageView);
        make.trailing.mas_equalTo(self.topView).offset(-15 * SCREENH6);
        make.height.mas_equalTo(1 * SCREENH6);
        make.top.mas_equalTo(self.iocnImageView.mas_bottom).offset(15 * SCREENH6);
    }];
    
    [self.commitTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.iocnImageView);
        make.trailing.mas_equalTo(self.lineView);
        make.height.mas_equalTo(75 * SCREENH6);
        make.top.mas_equalTo(self.lineView.mas_bottom).offset(1 * SCREENH6);
    }];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.view);
        make.top.mas_equalTo(self.topView.mas_bottom).offset(20 * SCREENH6);
        make.leading.trailing.mas_equalTo(self.topView);
    }];
    
    [self.shopImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.iocnImageView);
        make.top.mas_equalTo(self.bottomView).offset(20 * SCREENH6);
        make.width.mas_equalTo(23 * SCREENH6);
        make.height.mas_equalTo(19 * SCREENH6);
    }];
    
    [self.bottomTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.shopImageView.mas_trailing).offset(5 * SCREENH6);
        make.centerY.mas_equalTo(self.shopImageView);
    }];
    
    [self.exploreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.bottomView).offset(-15 * SCREENH6);
        make.centerY.mas_equalTo(self.bottomTitleLabel);
    }];
    
//    [self.conformLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(self.bottomTitleLabel);
//        make.top.mas_equalTo(self.bottomTitleLabel.mas_bottom).offset(15 * SCREENH6);
//    }];
//
//    [self.severLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(self.conformLabel);
//        make.top.mas_equalTo(self.conformLabel.mas_bottom).offset(10 * SCREENH6);
//    }];
//
//    [self.goodLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.leading.mas_equalTo(self.severLabel);
//        make.top.mas_equalTo(self.severLabel.mas_bottom).offset(10 * SCREENH6);
//    }];
}

- (UIView *)setupView{
    
    UIView * view = [UIView new];
    
    view.backgroundColor = ZRWhiteColor;
    view.layer.cornerRadius = 5;
    view.layer.masksToBounds = YES;
    view.userInteractionEnabled = YES;
    
    return view;
}

- (UILabel *)setupLabelWithString:(NSString *)string{
    
    UILabel * label = [UILabel new];
    
    label.textColor = ZRBlackColor;
    label.text = string;
    label.font = [UIFont systemFontOfSize:15 * SCREENH6];
    
    return label;
}

- (XHStarRateView *)setupStartViewWithFrame:(CGRect)frame{
    
    XHStarRateView * starRateView = [[XHStarRateView alloc] initWithFrame:frame];
    starRateView.isAnimation = NO; // 有动画
    starRateView.rateStyle = XHStarRateViewRateStyeFullStar; //允许不完整星评论
    //    starRateView.delegate = self;
    starRateView.currentRating = 0;
    starRateView.normol = @"star(4)";
    starRateView.userInteractionEnabled = YES;
    
    return starRateView;
}

#pragma mark - AddPictureViewDelegate
- (void)clickItemButton:(NSInteger )tag{
    
    self.count = tag;
    
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        
        self.alertVC.popoverPresentationController.sourceView = self.view;
        self.alertVC.popoverPresentationController.sourceRect = CGRectMake(10 * SCREENH6,kScreenH - 150 * SCREENH6,355 * SCREENH6,150 * SCREENH6);
        //            self.alertVC.modalPresentationStyle = UIModalPresentationFormSheet;
    }
    
    [self presentViewController:self.alertVC animated:YES completion:nil];
}

- (void)clickDeleteButton:(NSInteger )tag{
    
    [self.imgArray removeObjectAtIndex:tag - 1];
    
    if (self.imgArray.count > 2 && self.imgArray.count < 5) {
        
        self.addView.height = 165 * SCREENH6;
        self.topView.height = 335 * SCREENH6;
    }else if(self.imgArray.count > 5 && self.imgArray.count <= 9) {
        
        self.addView.height = 245 * SCREENH6;
        self.topView.height = 415 * SCREENH6;
    }else if(self.imgArray.count <= 2) {
        
        self.addView.height = 85 * SCREENH6;
        self.topView.height = 240 * SCREENH6;
    }
}

- (void)setupAlertVC{
    
    self.alertVC = [UIAlertController alertControllerWithTitle:@"" message:@"选择照片方式" preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction * camerAction = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        self->_imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
        
        [self presentViewController:self->_imagePickerController animated:YES completion:nil];
    }];
    
    UIAlertAction * albumsAction = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        self->_imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        
        [self presentViewController:self->_imagePickerController animated:YES completion:nil];
    }];
    
    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    [self.alertVC addAction:camerAction];
    [self.alertVC addAction:albumsAction];
    [self.alertVC addAction:cancelAction];
    
}

#pragma mark -实现图片选择器代理
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissViewControllerAnimated:YES completion:^{}];
    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage]; //通过key值获取到图片
    //给UIimageView赋值已经选择的相片
    NSData *frontImageData = UIImageJPEGRepresentation(image,0.5);
    NSString *base64Data = [frontImageData base64EncodedStringWithOptions:0];
    NSString * reslut = [NSString stringWithFormat:@"data:image/jpeg;base64,%@",base64Data];
    
    //上传图片到服务器--在这里进行图片上传的网络请求，这里不再介绍
    [[ZRNetworkTool sharedTool] uploadOneImgResultWithImg:reslut WithBlock:^(BOOL success, id responseData) {

        if (success) {

            if (self.count > 2 && self.count < 5) {
                
                self.addView.height = 200 * SCREENH6;
                self.topView.height = 350 * SCREENH6;
            }else if(self.count > 5 && self.count <= 9) {
                
                self.addView.height = 300 * SCREENH6;
                self.topView.height = 450 * SCREENH6;
            }
            
            self.addView.count = self.count;
            self.addView.buttonImage = image;
            
            NSString * string = [NSString stringWithFormat:@"%@",responseData[@"data"]];

            [self.imgArray addObject:string];
        }else{
            
            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                           message:responseData[@"message"]
                                                                    preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                  handler:^(UIAlertAction * action) {
                                                                      
                                                                  }];
            
            [alert addAction:defaultAction];
            [self presentViewController:alert animated:YES completion:nil];
        }
    }];
}

//当用户取消选择的时候，调用该方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker dismissViewControllerAnimated:YES completion:^{}];
}

#pragma mark - UITextViewDelegate
- (void)textViewDidEndEditing:(UITextView *)textView
{
    
    if(textView.text.length < 1){
        textView.text = @"对这次购物体验满意吗？可以在这里说说你的感受哦！";
        textView.textColor = ColorWithRGB(0xbebebe);
    }else{
        
        [textView resignFirstResponder];
    }
}

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if([textView.text isEqualToString:@"对这次购物体验满意吗？可以在这里说说你的感受哦！"]){
        textView.text=@"";
        textView.textColor=[UIColor blackColor];
    }
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return self.dataArray.count - 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    PublishCommitTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PublishCommitTableViewCell" forIndexPath:indexPath];
    
    PushCommitModel * model = self.dataArray[indexPath.row + 1];
    
    cell.titleLabel.text = model.merchants_comments_name;
    cell.ID = model.id;

    return cell;
}


- (void)didRightButton{
    
    int cout = self.totalStartView.currentRating;
    NSString * countString;
    
    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    
    for (PublishCommitTableViewCell *cell in self.tableView.visibleCells) {
        
        XHStarRateView * startView = cell.startView;
        
        int count = startView.currentRating;
        NSString * countStr = [NSString stringWithFormat:@"%d",count];
        NSString * ID = [NSString stringWithFormat:@"%@",cell.ID];
        if (count == 0) {
            
            countString = @"test";
        }
        [dict setObject:countStr forKey:ID];
    }
    
    NSLog(@"cout===%d",cout);
    NSLog(@"dict==%@",dict);
    
    if (cout == 0 || countString.length > 0) {
        
        UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                       message:@"请先完成星级评分"
                                                                preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                              handler:^(UIAlertAction * action) {
                                                                  
                                                              }];
        
        [alert addAction:defaultAction];
        [self presentViewController:alert animated:YES completion:nil];
    }else{
        
        NSString * totalStr = [NSString stringWithFormat:@"%d",cout];
        [dict setObject:totalStr forKey:self.IDStr];
        NSLog(@"totalStr==%@",dict);
        NSString * resString = [self convertToJsonData:dict.copy];
        NSCharacterSet *encodeUrlSet = [NSCharacterSet URLQueryAllowedCharacterSet];
        NSString *encodeUrl = [resString stringByAddingPercentEncodingWithAllowedCharacters:encodeUrlSet];
        NSString *str = [self.imgArray componentsJoinedByString:@","];
        NSString * user_id = DEF_GET_OBJECT(@"id");
        NSString * commit;
        if ([self.commitTextView.text isEqualToString:@"对这次购物体验满意吗？可以在这里说说你的感受哦！"]) {
            commit = @"";
        }else{
            
            commit = self.commitTextView.text;
        }
        NSDictionary * resDict = @{@"comment_user_id":user_id,@"comment_object_goods_order_id":self.ID,@"merchants_comment_rules":encodeUrl,@"comment_content":commit,@"comment_img":str};
        
        [[ZRNetworkTool sharedTool] commentsMerchantsGoodsWithDictory:resDict ResultWithBlock:^(BOOL success, id responseData) {
            
            if (success) {
                
                UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                               message:@"恭喜你评论成功！"
                                                                        preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                      handler:^(UIAlertAction * action) {
                                                                          
                                                                          [self.navigationController popViewControllerAnimated:YES];
                                                                      }];
                
                [alert addAction:defaultAction];
                [self presentViewController:alert animated:YES completion:nil];
            }else{
                
                UIAlertController* alert = [UIAlertController alertControllerWithTitle:@""
                                                                               message:responseData[@"message"]
                                                                        preferredStyle:UIAlertControllerStyleAlert];
                
                UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel
                                                                      handler:^(UIAlertAction * action) {
                                                                          
                                                                          
                                                                      }];
                
                [alert addAction:defaultAction];
                [self presentViewController:alert animated:YES completion:nil];
            }
        }];
    }
    
    
    
}

-(NSString *)convertToJsonData:(NSDictionary *)dict{
    
    NSError *error;
    
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
    
    NSString *jsonString;
    
    if (!jsonData) {
        
        NSLog(@"%@",error);
        
    }else{
        
        jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
        
    }
    
    NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
    
    NSRange range = {0,jsonString.length};
    
    //去掉字符串中的空格
    
    [mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
    
    NSRange range2 = {0,mutStr.length};
    
    //去掉字符串中的换行符
    
    [mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
    
    return mutStr;
}

@end
